package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.ApprovalConfig;
import com.ruoyi.system.mapper.ApprovalConfigMapper;
import com.ruoyi.system.service.IApprovalConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 审批流配置Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-21
 */
@Service
public class ApprovalConfigServiceImpl implements IApprovalConfigService 
{
    @Autowired
    private ApprovalConfigMapper approvalConfigMapper;

    /**
     * 查询审批流配置
     * 
     * @param id 审批流配置主键
     * @return 审批流配置
     */
    @Override
    public ApprovalConfig selectApprovalConfigById(Long id)
    {
        return approvalConfigMapper.selectApprovalConfigById(id);
    }

    /**
     * 查询审批流配置列表
     * 
     * @param approvalConfig 审批流配置
     * @return 审批流配置
     */
    @Override
    public List<ApprovalConfig> selectApprovalConfigList(ApprovalConfig approvalConfig)
    {
        return approvalConfigMapper.selectApprovalConfigList(approvalConfig);
    }

    /**
     * 新增审批流配置
     * 
     * @param approvalConfig 审批流配置
     * @return 结果
     */
    @Override
    public int insertApprovalConfig(ApprovalConfig approvalConfig)
    {
        approvalConfig.setCreateTime(DateUtils.getNowDate());
        return approvalConfigMapper.insertApprovalConfig(approvalConfig);
    }

    /**
     * 修改审批流配置
     * 
     * @param approvalConfig 审批流配置
     * @return 结果
     */
    @Override
    public int updateApprovalConfig(ApprovalConfig approvalConfig)
    {
        approvalConfig.setUpdateTime(DateUtils.getNowDate());
        return approvalConfigMapper.updateApprovalConfig(approvalConfig);
    }

    /**
     * 批量删除审批流配置
     * 
     * @param ids 需要删除的审批流配置主键
     * @return 结果
     */
    @Override
    public int deleteApprovalConfigByIds(Long[] ids)
    {
        return approvalConfigMapper.deleteApprovalConfigByIds(ids);
    }

    /**
     * 删除审批流配置信息
     * 
     * @param id 审批流配置主键
     * @return 结果
     */
    @Override
    public int deleteApprovalConfigById(Long id)
    {
        return approvalConfigMapper.deleteApprovalConfigById(id);
    }

    /**
     * 根据模块代码查询配置
     * 
     * @param moduleCode 模块代码
     * @return 审批流配置
     */
    @Override
    public ApprovalConfig selectByModuleCode(String moduleCode)
    {
        return approvalConfigMapper.selectByModuleCode(moduleCode);
    }

    /**
     * 检查模块是否启用审批
     * 
     * @param moduleCode 模块代码
     * @return 是否启用
     */
    @Override
    public boolean isModuleEnabled(String moduleCode)
    {
        Integer enabled = approvalConfigMapper.checkModuleEnabled(moduleCode);
        return enabled != null && enabled == 1;
    }
}
